/*
 * @Author: 无聊 7989314+Hwz1997@user.noreply.gitee.com
 * @Date: 2025-09-03 02:27:13
 * @LastEditors: 无聊 7989314+Hwz1997@user.noreply.gitee.com
 * @LastEditTime: 2025-09-03 02:31:05
 * @FilePath: \keep_motion_api\controllers\product\categories.controller.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const { ProductCategory } = require('@/models/product');
const getCategories = async (req, res) => {
  try {
    const { parent_id, offset, limit } = req.query;
    const { rows, total } = await ProductCategory.getCategories(parent_id, offset, limit);
    res.json({ rows, total });
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
}
const createCategory = async (req, res) => {
  try {
    const data = req.body;
    const category = await ProductCategory.createCategory(data);
    res.json(category);
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
}
const updateCategory = async (req, res) => {
  try {
    const { id } = req.params;
    const data = req.body;
    const category = await ProductCategory.updateCategory(id, data);
    res.json(category);
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
}
const deleteCategory = async (req, res) => {
  try {
    const { id } = req.params;
    const category = await ProductCategory.deleteCategory(id);
    res.json(category);
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
}
const updateOrder = async (req, res) => {
  try {
    const { id } = req.params;
    const data = req.body;
    const category = await ProductCategory.updateOrder(id, data);
    res.json(category);
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
}

module.exports = {
  getCategories,
  createCategory,
  updateCategory,
  deleteCategory,
  updateOrder
}
